package main

import (
	"fmt"
	"github.com/hashicorp/consul/api"
)

func main() {
	//从注册中心获取到用户服务的信息
	cfg := api.DefaultConfig()
	cfg.Address = fmt.Sprintf("%s:%d", "172.16.100.187", 8500)

	client, err := api.NewClient(cfg)
	if err != nil {
		panic(err)
	}

	data, err := client.Agent().ServicesWithFilter(fmt.Sprintf("Service == \"%s\"", "user-web"))
	for _, value := range data {
		fmt.Println(value.Address)
		fmt.Println(value.Port)
	}
}
